package com.springmvc.demo.controller;


import com.springmvc.demo.model.MessageInfo;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RequestMapping("/message")
@RestController
public class MessageController {
    private List<MessageInfo> messageInfos = new ArrayList<>();

    @RequestMapping("/publish")
    public boolean subMessage(MessageInfo message) {
        if(!StringUtils.hasLength(message.getFrom())
            || !StringUtils.hasLength(message.getFrom())
            || !StringUtils.hasLength(message.getTo())) {
            return false;
        }
        messageInfos.add(message);
        return true;
    }

    @RequestMapping("/getList")
    public List<MessageInfo> getList() {
        return messageInfos;
    }
}
